<?php
$this->title = '登录';
?>
<body class="m-login">

<ul>
    <li><input type="text" placeholder="手机号" /><a href="javascript:;" id="J_sendCode">发送验证码</a></li><!-- <span>3</span> S后重发 -->
    <li><input type="text" id="J_code" placeholder="输入验证码" /></li>
</ul>

<h4><button type="submit" onclick="submit();">绑定</button></h4>


<div class="m-nav f-cb u-bg1">
    <a href="/" class="z-on">首页</a>
    <a href="/web/category/category-list?shop_id=1001">分类</a>
    <a href="/web/cart/view?shop_id=<?= '1001'//yii::$app->session->get('shop_id')?>">购物车</a>
    <a href="/web/my">我的</a>
</div>

<script>
    $(function(){

        // 发送验证码
        var lock = 'z-lock';
        $('#J_sendCode').on('tap', function(){

            var _this = $(this);

            // 获取电话号码
            var _phone = $.trim(_this.prev().val());
            // if(_phone.length < 11) return !1;

            // 防止重复点击
            if(_this.hasClass(lock)) return !1;

            // 发送操作
            $.ajax({
                url: 'send?funcName=?', dataType:'jsonp',
                data:{'phone':_phone}, timeout:5000,
                success: function(_info){}
            });

            // lock & change noteMsg
            _this.addClass(lock).html('<span>60</span> S后重发');

            var _tmr = _this.find('span');

            var _int = setInterval(function(){

                var _i = Math.ceil(_tmr.text());

                if(_i <= 0){
                    clearInterval(_int);
                    _this.removeClass(lock).html('发送验证码');
                }

                _i--
                _tmr.text(_i);

            }, 1000);



        });
    });
    function submit()
    {
        var mobile = $.trim($('#J_sendCode').prev().val());
        var code = $('#J_code').val();
        $.get("<?=\yii\helpers\Url::to(['login'])?>", {mobile:mobile, code:code}, function(data) {
            if(data == 1) {
                window.location.href = '/web/default/home';
            }else {
                alert(data);
            }
        })
    }
</script>
</body>
